Skip to content

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jul 31, 2021

The FromJSON instance is already capable of handling the decimal representation. This change supports outputting the decimal representation when that is more compact.

@newhoggy
Copy link
Contributor Author

λ> toJSON (1 % 10)
Number 0.1
λ> toJSON (1 % 3)
Object (fromList [("denominator",Number 3.0),("numerator",Number 1.0)])

Copy link

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

https://hackage.haskell.org/package/scientific-0.3.7.0/docs/Data-Scientific.html#v:fromRationalRepetend

I agree that matching on Right (s, Nothing) looks like the right choice.

@bergmark
Copy link
Collaborator

Thanks!

I think I need some convincing for this. It is a breaking change for anyone using this instance. The reason to only adapt FromJSON may have been because we do not consider that breaking.

I would lean towards having this in a newtype.

@newhoggy
Copy link
Contributor Author

What would you choose as the name of the newtype?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants